import java.io.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2024-06-28
 * Time: 20:07
 */
public class Deom2 {
    public static void main(String[] args) throws IOException {
        File file = new File("./text1.txt");
        file.createNewFile();
        InputStream inputStream = new FileInputStream(file);
        //InputStream inputStream1 = new FileInputStream("./1.png");
        //版本1：
        /*while(true) {
            int a = inputStream.read();
            if(a == -1) {
                //读取完毕
                break;
            }
            System.out.printf("0x%X ",a);
        }*/
        //版本2：
       /*byte[] bytes = new byte[1024];
        int b = inputStream1.read(bytes);
        System.out.println("b = " + b);
        for (int i = 0; i < b; i++) {
            System.out.printf("0x%X ",bytes[i]);
        }*/
        //版本3：
       /* byte[] bytes = new byte[1024];
        int c = inputStream1.read(bytes,0,10);
        for (int i = 0; i < c; i++) {
            System.out.printf("ox%x ",bytes[i]);
        }
        inputStream1.close();*/
        try(InputStream inputStream1 = new FileInputStream("./1.png")){
            byte[] bytes = new byte[1024];
            int c = inputStream1.read(bytes,0,10);
            for (int i = 0; i < c; i++) {
                System.out.printf("ox%x ",bytes[i]);
            }
        }
    }
}
